﻿var tplHelper = {
    target: null,
    SetTemplate: function (id, text) {
        if (this.target) {
            $(this.target).find(".text").val(text).siblings(".value").val(id);
        }
    },
    Select: function (t, e) {
        this.target = t;
        var param = $(e).data("param").split("|")
        var url = "?type=" + param[0] + "&model=" + param[1];
        layer.open({
            type: 2,
            area: ['900px', '475px'],
            content: "/Lgm/SelectTemplate" + url,
        })
    },
    Clear: function () {
        this.target = null;
    }
}

var laySwitch = {
    render: function (n, e) {
        switch (n) {
            case 1:
                return "<div class='layui-unselect layui-form-switch layui-form-onswitch' lay-skin='_switch' lay-event='" + e + "'><em>ON</em><i></i></div>";
                break;
            default:
                return "<div class='layui-unselect layui-form-switch' lay-skin='_switch' lay-event='" + e + "'><em>OFF</em><i></i></div>";
        }
    },
    do: function (o) {
        if (!o.data) {
            o.data = {};
            o.data["Id"] = o.obj.data.Id;
            o.data[o.key] = o.obj.data[o.key] == 1 ? 0 : 1;
        }
        o.obj.data[o.key] = o.data[o.key];
        lg.request({
            url: o.url,
            method: "post",
            data: o.data,
            success: function (d) {
                if (d.code == 0) {
                    if (o.refresh) {
                        page.laytable.reload();
                    } else {
                        o.obj.update(o.obj.data);
                    }
                    layer.msg("操作成功!", { icon: 1 });
                } else {
                    layer.msg(d.msg, { icon: 2 })
                }
            }
        });
    }
}

